#pragma once
#include "renderer.h"

namespace krryn{
namespace view{
	renderer::renderer() : m_Quad(0){}

	render_operation renderer::get_dummy_quad(){
		if(!m_Quad){
			m_Quad = new render_operation();
			m_Quad->m_DrawMode = mode_triangle_list;
			int l_Offset = 0;
			l_Offset = m_Quad->m_Format.append_element(l_Offset, type_float3, semantic_position);
			l_Offset = m_Quad->m_Format.append_element(l_Offset, type_float2, semantic_texture_coordinates);
			m_Quad->m_IndexBuffer = create_index_buffer(6, index_32bit);
			m_Quad->m_VertexBuffer = create_vertex_buffer(5 * sizeof(float), 4);

			int *ib = (int*)m_Quad->m_IndexBuffer->lock(hardware_buffer::write);

			*ib++ = 0; *ib++ = 1; *ib++ = 2;
			*ib++ = 0; *ib++ = 2; *ib++ = 3;

			m_Quad->m_IndexBuffer->unlock();

			float *fb = (float*)m_Quad->m_VertexBuffer->lock(hardware_buffer::write);

			// pos
			*fb++ = -1; *fb++ = -1; *fb++ =  0;
			*fb++ = 0; *fb++ = 0;

			// pos
			*fb++ = 1; *fb++ = -1; *fb++ = 0;
			*fb++ = 1; *fb++ = 0;

			// pos
			*fb++ = 1; *fb++ = 1; *fb++ = 0;
			*fb++ = 1; *fb++ = 1;

			// pos
			*fb++ = -1; *fb++ = 1; *fb++ = 0;
			*fb++ = 0; *fb++ = 1;

			m_Quad->m_VertexBuffer->unlock();
		}

		return *m_Quad;
	}
}
}